#include<reg51.h>

#define NODE1_ADDR 1
unsigned char pointer = 0;

sbit key = P1^0;

unsigned char str[] = {"0123456789ABCDEF"};

unsigned char num[16]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xd8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};


void delay(unsigned int time)
{
    unsigned char i, j;
    for (i = 0; i < 130; i++)
    {
        for (j = 0; i < time; j++);
    }
}

void main()
{
    SCON = 0xd0;
    TMOD = 0x20; 
    TH1 = TL1 = 0xfd;
    TR1 = 1;
    while (1)
    {
        P1 = 0xff;
        while(P1 == 0xff);
        if (P1 == 0xfe)
        {
            delay(200);
            TB8 = 1; 
            SBUF = NODE1_ADDR;
            while(!TI);
            TI = 0; 
            TB8 = 0;
            SBUF = str[pointer++];
            if (pointer>=16)
            {
                pointer = 0;
            }
            while (!TI);
            TI = 0;
            P0 = num[pointer];
        }
    }
}

